import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'node:path'
import autoprefixer from 'autoprefixer'

export default defineConfig(() => {
  return {
    plugins: [vue()],
    base: './',
    css: {
      postcss: {
        plugins: [
          autoprefixer({}), // add options if needed
        ],
      },
    },
    resolve: {
      alias: [
        // webpack path resolve to vitejs
        {
          find: /^~(.*)$/,
          replacement: '$1',
        },
        {
          find: '@/',
          replacement: `${path.resolve(__dirname, 'src')}/`,
        },
        {
          find: '@',
          replacement: path.resolve(__dirname, '/src'),
        },
      ],
      extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue', '.scss'],
    },
    server: {
      host: '127.0.0.1',
      proxy: {
        '/api': {
          // target: 'http://192.168.110.204:5200/', //chao本地
          // target: 'http://172.18.159.92:5200/',
          target: 'http://10.204.253.11:5200/',
          // target: 'http://192.168.1.203:8081/',
          // target: 'http://192.168.110.204:8081·/',
          // target: 'http://192.168.124.39:5200/',
          // target: 'http://10.204.170.214:5200/',
          changeOrigin: true, //开启代理，允许跨域
          //重写路径
          //rewrite: (path) => path.replace(/^\/api/, "")
        },
        '/sign-in': {
          // target: 'http://192.168.110.204:5200/',
          // target: 'http://172.18.159.92:5200/',
          target: 'http://10.204.253.11:5200/',
          // target: 'http://192.168.110.204:5200/',
          // target: 'http://192.168.124.39:5200/',
          // target: 'http://10.204.170.214:5200/',
          changeOrigin: true, //开启代理，允许跨域
          cookieDomainRewrite: {
            '*': '',
          },
        },
        '/dmp-datafactory': {
          target: 'http://10.204.253.12:8085/',// 水务加代理地址
          changeOrigin: true, //开启代理，允许跨域
          cookieDomainRewrite: {
            '*': '',
          },
        },
        '/kafka': {
          target: 'http://192.168.110.204:8080/',// 后台李延超本地
          changeOrigin: true, //开启代理，允许跨域
          cookieDomainRewrite: {
            '*': '',
          },
        },
        '/hd': {
          target: 'http://10.204.253.1:8086/',// 和达代理地址
          changeOrigin: true, //开启代理，允许跨域
          // cookieDomainRewrite: {
          //   '*': '',
          // },
        },
        '/leak3': {
          target: 'http://10.204.253.1:8086/',// 和达代理地址
          changeOrigin: true, //开启代理，允许跨域
          // cookieDomainRewrite: {
          //   '*': '',
          // },
        },
        '/video': {
          target: 'http://10.204.253.11:5200/',// 92测试环境监控组态图监控
          changeOrigin: true, //开启代理，允许跨域
          // cookieDomainRewrite: {
          //   '*': '',
          // },
        },
        '/RemoteMonitoring': {
          target: 'http://10.204.253.11:5200/',// 92测试环境监控组态图
          changeOrigin: true, //开启代理，允许跨域
          // cookieDomainRewrite: {
          //   '*': '',
          // },
        },
        // 
        '/subzone': {
          target: 'http://10.204.253.11:8081/',// 92测试环境-分区供水量
          changeOrigin: true, //开启代理，允许跨域
          // cookieDomainRewrite: {
          //   '*': '',
          // },
        },
      },
      port: 5176,
    },
    optimizeDeps: {
      include: ['gifler']
    }
  }
})
